package com.example.androidbighomework.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.androidbighomework.R;
import com.example.androidbighomework.bean.HomeDataBean;

public class dongtaiBaseAdapter extends BaseAdapter {
    @Override
    public int getCount() {
        return HomeDataBean.getInstance().getHomeContentText().length;
    }

    @Override
    public Object getItem(int position) {
        return HomeDataBean.getInstance().getHomeContentText()[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder hoder;
        if(convertView==null){
            convertView=View.inflate(parent.getContext(), R.layout.list_dongtai_item_layout,null);
            hoder=new ViewHoder();
            hoder.image=convertView.findViewById(R.id.list_iv_dongtai_img);
            hoder.content=convertView.findViewById(R.id.list_tv_dongtai_content);
            convertView.setTag(hoder);
        }
        else {
            hoder=(ViewHoder)convertView.getTag();
        }
        hoder.content.setText(HomeDataBean.getInstance().getHomeContentText()[position]);
        hoder.image.setBackgroundResource(HomeDataBean.getInstance().getHomeContentImage()[position]);
        return convertView;
    }
    class ViewHoder{
        ImageView image;
        TextView content;
    }
}
